import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import chunk from './pathApi'
import Layout from '@/layout/index.vue'
import rouetrAdd from '@/router/pageOptions'
import dt from '@dt/dt'

Vue.use(VueRouter)
//解决编程式路由往同一地址跳转时会报错的情况
// const originalPush = VueRouter.prototype.push
// const originalReplace = VueRouter.prototype.replace
// //push
// VueRouter.prototype.push = function push(location, onResolve, onReject) {
// 	if (onResolve || onReject)
// 		return originalPush.call(this, location, onResolve, onReject)
// 	return originalPush.call(this, location).catch((err) => err)
// }
// //replace
// VueRouter.prototype.replace = function push(location, onResolve, onReject) {
// 	if (onResolve || onReject)
// 		return originalReplace.call(this, location, onResolve, onReject)
// 	return originalReplace.call(this, location).catch((err) => err)
// }
const routes: Array<RouteConfig> = [
	{
		path: '/',
		component: Layout,
		redirect: '/login',
		children: rouetrAdd,
	},
	{
		path: '/login',
		component: chunk.modules('login/Login'),
		name: 'login',
		meta: {
			auth: false,
			title: '欢迎登录同策网工作台',
		},
	},
	// {
	// 	path: '*',
	// 	redirect: 'home/crimeSceneList',
	// 	meta: {
	// 		title: '404',
	// 	},
	// },
]

const router = new VueRouter({
	mode: 'history',
	routes,
	// scrollBehavior(to, from, savedPosition) { //路由跳转前是否有滚动，回退按钮回来时是否定位到滚动页面
	//   if (savedPosition) {
	//     return savedPosition
	//   } else {
	//     return {
	//       x: 0,
	//       y: 0
	//     }
	//   }
	// },
})
dt.router = router


export default router
